package com.trace.pplos.load.listener;

import com.trace.pplos.load.scheduler.CosScheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Project Name:pplos
 * Package Name:com.trace.pplos.load.listener
 *
 * @author：zhouqilin
 * @date：2017/8/6 10:44
 * Copyright (c) 2017,jv.com.cn All Rights Reserved.
 */
@Configuration
public class SchedulerListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    public CosScheduler cosScheduler;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            cosScheduler.scheduleJobs();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        return schedulerFactoryBean;
    }
}
